dojo.provide('snareworks.SoundUtils');

dojo.require('snareworks.MGUtils');

dojo.declare("snareworks.SoundUtils", null, {
	
	RIGHT_SOUNDS: [
		'sounds/right/yay_z.mp3',
		'sounds/right/applause2_x.mp3',
		'sounds/right/baby_x.mp3',
		'sounds/right/bill_ted_excellent.mp3',
		'sounds/right/cheering.mp3',
		'sounds/right/fanfare_x.mp3',
		'sounds/right/infinity.mp3',
		'sounds/right/spaceballs_schwartz1.mp3',
		'sounds/right/success.mp3',
		'sounds/right/taught_u_well.mp3',
		'sounds/right/willy_wonka_puzzle.mp3',
		'sounds/right/woow_x.mp3'
	],
	
	WRONG_SOUNDS: [
		'sounds/wrong/willy_wonka_you_lose.mp3',
		'sounds/wrong/awwww.mp3',
		'sounds/wrong/blip.mp3',
		'sounds/wrong/boo.mp3',
		'sounds/wrong/car_crash.mp3',
		'sounds/wrong/fade_x.mp3',
		'sounds/wrong/fart_z.mp3',
		'sounds/wrong/gasp_ohhh.mp3',
		'sounds/wrong/general_direction.mp3',
		'sounds/wrong/honk_honk_x.mp3',
		'sounds/wrong/inconceivable.mp3',
		'sounds/wrong/lord_of_rings1_task.mp3',
		'sounds/wrong/meant_to.mp3',
		'sounds/wrong/scream_male.mp3'
	],
	
	COMPLETE_SOUND: 'sounds/complete.mp3',
	
	VOLUME: 25,
	
	constructor: function() {
		this.mg = new snareworks.MGUtils();
		this.initSounds();
	},
	
	initSounds: function() {
		this.mg.shuffle(this.RIGHT_SOUNDS);
		this.RIGHT_SOUNDS.playIndex = 0;
		this.mg.shuffle(this.WRONG_SOUNDS);
		this.WRONG_SOUNDS.playIndex = 0;
	},
	
	playRightSound: function() {
		this.playSoundFromArray(this.RIGHT_SOUNDS);
	},
	
	playWrongSound: function() {
		this.playSoundFromArray(this.WRONG_SOUNDS);
	},
	
	playSoundFromArray: function(array) {
		var index = array.playIndex;
		var mp3 = array[index];
		index = (index + 1) % array.length;
		array.playIndex = index;
		this.playMP3(mp3);
	},
	
	playMP3: function(mp3) {
		if (this.previousSound) {
			this.previousSound.stop();
		}
		var sound = soundManager.getSoundById(mp3);
		if (sound == null) {
			sound = soundManager.createSound({
				 id: mp3,
				 url:mp3
			});
		}
		this.previousSound = sound;
		sound.play({volume: this.VOLUME});
	}
	
});
